package com.chaosj.skill.zipkin.interceptor

import brave.Tracing
import brave.propagation.Propagation
import brave.propagation.TraceContext
import com.chaosj.skill.zipkin.context.ApplicationContext

/**
 * @Description:
 * @author: caoyangjie
 * @date: 2019年12月2019/12/6日 09:26
 * @Copyright: © 赢时胜
 */
abstract class AbstractTraceInterceptor<C> implements ITracerInterceptor<C,String>{
    /**
     * 128 or 64-bit trace ID lower-hex encoded into 32 or 16 characters (required)
     */
    static final String TRACE_ID_NAME = "X-B3-TraceId"

    @Override
    C injector(C carrier) {
        TraceContext traceContext = ApplicationContext.getBean(Tracing.class).tracer().nextSpan().context()
        Propagation.B3_STRING.injector(getSetter()).inject(traceContext,carrier)
        carrier
    }
}
